<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="对象复习.js"></script>
</head>

<body>
    <a href="https://baidu.com" class="aa" style="color: red" target="_blank">百度一下</a>
    <table border="1" cellspacing='0'>

        <thead>
            <th>英雄名字</th>
            <th>英雄位置</th>
            <th>技能</th>
            <th>经验值</th>
        </thead>
        <tbody>

        </tbody>
    </table>
</body>
<script>
    var tbody = document.querySelector('tbody')
    var data = [{
        "name": "李白",
        "position": "刺客",
        "skill": "青莲剑歌",
        "exp": 500
    }, {
        "name": "貂蝉",
        "position": "刺客/法师",
        "skill": "绽·风华",
        "exp": 350
    }, {
        "name": "鲁班1",
        "position": "射手",
        "skill": "空中支援",
        "exp": 800
    }, {
        "name": "鲁班1",
        "position": "射手",
        "skill": "空中支援",
        "exp": 800
    }];

    for (var i = 0; i < data.length; i++) {
        var tr = document.createElement('tr')
            // tr.innerHTML = `<td>${data[i].name}</td>
            //     <td>${data[i].position}</td>
            //     <td>${data[i].skill}</td>
            //     <td>${data[i].exp}</td>`
            //通过循环获取当前元素的下标
        for (var j in data[i]) {
            // 创建一个td
            td = document.createElement('td')
                //给td里面插入文字，值为data[i][j]
            td.innerText = data[i][j]
                //td插入到tr
            tr.append(td)
        }

        tbody.append(tr)
    }
</script>


</html>